home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / Soundtracker v2.6.adf / Replay26.s < prev    next >
Text File  |  1991-10-09  |  11KB  |  552 lines

  1. **********************************************
  2. *
  3. * Soundtracker Module-Player
  4. *   for Soundtracker V2.6
  5. *
  6. * SEKA version
  7. * (Devpac: replace 'blk' with 'dcb' (sic!) )
  8. *
  9. * last change: 03-Nov-90 mtn
  10. *
  11. **********************************************
  12. * Note: mt_init has to be called up with the
  13. * address of the module in A0 !!
  14. **********************************************
  15.  
  16. * equates for voice-structure *
  17. mt_cmdperiod=0                ;period
  18. mt_cmd=2                ;instr/cmd
  19. mt_cmdpar=3                ;cmd-parameter
  20. mt_sampleadr=4                ;address of sample
  21. mt_samplelen=8                ;length of sample
  22. mt_samplerep=$a                ;address of repeat-part
  23. mt_samplerepl=$e            ;length of repeat-part
  24. mt_period=$10                ;period to play
  25. mt_volume=$12                ;volume to set
  26. mt_dmabit=$14                ;dmabit for channel
  27. mt_slidedir=$16                ;slide up/down
  28. mt_slidespeed=$17            ;speed of slide
  29. mt_slidedest=$18            ;slide to period x
  30. mt_vibamp=$1a                ;vibrato amplitude
  31. mt_vibcount=$1b                ;counter for vibrato
  32. mt_voicelen=$1c
  33.  
  34. * equates for global player data-structure *
  35. mt_data=0                ;address of module
  36. mt_pattpos=4                ;current position
  37. mt_dmacon=6                ;dma-bits
  38. mt_speedEven=8                ;current speed (even frames)
  39. mt_speedOdd=9                ; -"- (odd frames)
  40. mt_songpos=$a                ;position-counter
  41. mt_counter=$b                ;frame-counter
  42. mt_break=$c                ;flag for pattern-break
  43. mt_datalen=$e
  44.  
  45. mt_init:
  46.     movem.l    d0-d1/a0-a2/a4,-(SP)
  47.     lea    mt_playerdata(PC),a4
  48.     clr.l    mt_data(a4)
  49.     cmp.l    #'MTN'*256,$5b8(a0)
  50.     bne    mt_initerror
  51.     move.l    a0,mt_data(a4)
  52.  
  53.     lea    $3b8(a0),a1
  54.     moveq    #0,d1
  55.     move.w    #$1ff,d0
  56. mt_loop:
  57.     cmp.b    (a1,d0.w),d1
  58.     bhi.s    mt_nothigh
  59.     move.b    (a1,d0.w),d1
  60. mt_nothigh:
  61.     dbf    d0,mt_loop
  62.     addq.b    #1,d1
  63.  
  64.     lea    mt_samplestarts(PC),a1
  65.     lsl.l    #8,d1
  66.     lea    (a0,d1.l),a2
  67.     add.w    #$5bc,a2
  68.     moveq    #$1e,d0
  69. mt_lop3:clr.l    (a2)
  70.     move.l    a2,(a1)+
  71.     moveq    #0,d1
  72.     move.w    42(a0),d1
  73.     add.l    d1,d1
  74.     add.l    d1,a2
  75.     add.w    #$1e,a0
  76.     dbf    d0,mt_lop3
  77.  
  78.     or.b    #2,$bfe001
  79.     move.b    #$06,mt_speedEven(a4)
  80.     move.b    #$06,mt_speedOdd(a4)
  81.     lea    mt_voice1(PC),a0
  82.     move.w    #$0001,mt_dmabit(a0)
  83.     lea    mt_voice2(PC),a0
  84.     move.w    #$0002,mt_dmabit(a0)
  85.     lea    mt_voice3(PC),a0
  86.     move.w    #$0004,mt_dmabit(a0)
  87.     lea    mt_voice4(PC),a0
  88.     move.w    #$0008,mt_dmabit(a0)
  89.     lea    $dff0a8,a0
  90.     clr.w    (a0)
  91.     clr.w    $10(a0)
  92.     clr.w    $20(a0)
  93.     clr.w    $30(a0)
  94.     clr.b    mt_songpos(a4)
  95.     clr.b    mt_counter(a4)
  96.     clr.w    mt_pattpos(a4)
  97. mt_initerror:
  98.     movem.l    (SP)+,d0-d1/a0-a2/a4
  99.     rts
  100.  
  101. mt_end:
  102.     move.l    a0,-(SP)
  103.     lea    $dff0a8,a0
  104.     clr.w    (a0)
  105.     clr.w    $10(a0)
  106.     clr.w    $20(a0)
  107.     clr.w    $30(a0)
  108.     move.w    #$f,$96-$a8(a0)
  109.     move.l    (SP)+,a0
  110.     rts
  111.  
  112. mt_music:
  113.     movem.l    d0-d5/a0-a6,-(SP)
  114.     lea    mt_playerdata(PC),a4
  115.     move.l    mt_data(a4),d0
  116.     beq    mt_playerror
  117.     move.l    d0,a0
  118.     addq.b    #1,mt_counter(a4)
  119.     move.b    mt_counter(a4),d0
  120.     move.w    mt_pattpos(a4),d1
  121.     lsr.w    #2,d1
  122.     and.w    #1,d1
  123.     move.b    mt_speedEven(a4,d1.w),d1
  124.     cmp.b    d1,d0
  125.     blt.s    mt_nonew
  126.     clr.b    mt_counter(a4)
  127.     bra    mt_getnew
  128.  
  129. mt_nonew:
  130.     lea    mt_voice1(PC),a6
  131.     lea    $dff0a0,a5
  132.     bsr    mt_checkcom
  133.     lea    mt_voice2(PC),a6
  134.     lea    $dff0b0,a5
  135.     bsr    mt_checkcom
  136.     lea    mt_voice3(PC),a6
  137.     lea    $dff0c0,a5
  138.     bsr    mt_checkcom
  139.     lea    mt_voice4(PC),a6
  140.     lea    $dff0d0,a5
  141.     bsr    mt_checkcom
  142.     bra    mt_endr
  143.  
  144. mt_arpeggio:
  145.     moveq    #0,d0
  146.     move.b    mt_counter(a4),d0
  147.     divu    #$3,d0
  148.     swap    d0
  149.     tst.w    d0
  150.     beq.s    mt_arp2
  151.     cmp.w    #2,d0
  152.     beq.s    mt_arp1
  153.  
  154.     moveq    #0,d0
  155.     move.b    mt_cmdpar(a6),d0
  156.     lsr.b    #4,d0
  157.     bra.s    mt_arp3
  158. mt_arp1:moveq    #0,d0
  159.     move.b    mt_cmdpar(a6),d0
  160.     and.b    #$f,d0
  161.     bra.s    mt_arp3
  162. mt_arp2:move.w    mt_period(a6),d2
  163.     bra.s    mt_arp4
  164. mt_arp3:add.w    d0,d0
  165.     moveq    #0,d1
  166.     move.w    mt_period(a6),d1
  167.     lea    mt_periods(PC),a0
  168.     moveq    #$24,d3
  169. mt_arploop:
  170.     move.w    (a0,d0.w),d2
  171.     cmp.w    (a0),d1
  172.     bge.s    mt_arp4
  173.     addq.l    #2,a0
  174.     dbf    d3,mt_arploop
  175.     rts
  176. mt_arp4:move.w    d2,6(a5)
  177.     rts
  178.  
  179. mt_getnew:
  180.     clr.w    mt_dmacon(a4)
  181.  
  182.     lea    $dff0a0,a5
  183.     lea    mt_voice1(pc),a6
  184.     moveq    #0,d5
  185.     bsr.s    mt_playvoice
  186.     lea    $dff0b0,a5
  187.     lea    mt_voice2(pc),a6
  188.     moveq    #1,d5
  189.     bsr.s    mt_playvoice
  190.     lea    $dff0c0,a5
  191.     lea    mt_voice3(pc),a6
  192.     moveq    #2,d5
  193.     bsr.s    mt_playvoice
  194.     lea    $dff0d0,a5
  195.     lea    mt_voice4(pc),a6
  196.     moveq    #3,d5
  197.     bsr.s    mt_playvoice
  198.     bra    mt_setdma
  199.  
  200. mt_playvoice:
  201.     move.l    mt_data(a4),a0
  202.     lea    12(a0),a3
  203.     lea    $3b8(a0),a2
  204.     lea    $5bc(a0),a0
  205.  
  206.     moveq    #0,d0
  207.     moveq    #0,d1
  208.     move.b    mt_songpos(a4),d0
  209.     lsl.w    #2,d0
  210.     add.w    d0,a2
  211.     move.b    (a2,d5.w),d1
  212.     lsl.l    #8,d1
  213.     add.w    mt_pattpos(a4),d1
  214.  
  215.     move.l    (a0,d1.l),mt_cmdperiod(a6)
  216.     addq.l    #4,d1
  217.     moveq    #0,d2
  218.     move.b    mt_cmd(a6),d2
  219.     and.b    #$f0,d2
  220.     lsr.b    #4,d2
  221.     move.b    mt_cmdperiod(a6),d0
  222.     and.b    #$f0,d0
  223.     or.b    d0,d2
  224.     tst.b    d2
  225.     beq.s    mt_setregs
  226.     moveq    #0,d3
  227.     lea    mt_samplestarts(PC),a1
  228.     move.l    d2,d4
  229.     subq.l    #$1,d2
  230.     lsl.l    #2,d2
  231.     mulu    #$1e,d4
  232.     move.l    (a1,d2.l),mt_sampleadr(a6)
  233.     move.w    (a3,d4.l),mt_samplelen(a6)
  234.     move.w    $2(a3,d4.l),mt_volume(a6)
  235.     move.w    $4(a3,d4.l),d3
  236.     tst.w    d3
  237.     beq.s    mt_noloop
  238.     move.l    mt_sampleadr(a6),d2
  239.     add.w    d3,d3
  240.     add.l    d3,d2
  241.     move.l    d2,mt_samplerep(a6)
  242.     move.w    $4(a3,d4.l),d0
  243.     add.w    $6(a3,d4.l),d0
  244.     move.w    d0,mt_samplelen(a6)
  245.     move.w    $6(a3,d4.l),mt_samplerepl(a6)
  246.     move.w    mt_volume(a6),8(a5)
  247.     bra.s    mt_setregs
  248. mt_noloop:
  249.     move.l    mt_sampleadr(a6),d2
  250.     add.l    d3,d2
  251.     move.l    d2,mt_samplerep(a6)
  252.     move.w    $6(a3,d4.l),mt_samplerepl(a6)
  253.     move.w    mt_volume(a6),8(a5)
  254. mt_setregs:
  255.     move.w    mt_cmdperiod(a6),d0
  256.     and.w    #$fff,d0
  257.     beq    mt_checkcom2
  258.     move.b    mt_cmd(a6),d0
  259.     and.b    #$f,d0
  260.     cmp.b    #$3,d0
  261.     bne.s    mt_setperiod
  262.     bsr    mt_setmyport
  263.     bra    mt_checkcom2
  264. mt_setperiod:
  265.     move.w    mt_cmdperiod(a6),mt_period(a6)
  266.     and.w    #$fff,mt_period(a6)
  267.     move.w    mt_dmabit(a6),$dff096
  268.     clr.b    mt_vibcount(a6)
  269.  
  270.     move.l    mt_sampleadr(a6),(a5)
  271.     move.w    mt_samplelen(a6),4(a5)
  272.     move.w    mt_period(a6),d0
  273.     and.w    #$fff,d0
  274.     move.w    d0,6(a5)
  275.     move.w    mt_dmabit(a6),d0
  276.     or.w    d0,mt_dmacon(a4)
  277.     bra    mt_checkcom2
  278.  
  279. mt_setdma:
  280.     lea    $dff000,a5
  281.     moveq    #8,d3                ;less than this can cause trouble
  282.     bsr    mt_waitscan
  283.     move.w    mt_dmacon(a4),d0
  284.     or.w    #$8000,d0
  285.     move.w    d0,$96(a5)
  286.     moveq    #1,d3
  287.     bsr    mt_waitscan
  288.     lea    mt_voice4(pc),a6
  289.     move.l    mt_samplerep(a6),$d0(a5)
  290.     move.w    mt_samplerepl(a6),$d4(a5)
  291.     lea    mt_voice3(pc),a6
  292.     move.l    mt_samplerep(a6),$c0(a5)
  293.     move.w    mt_samplerepl(a6),$c4(a5)
  294.     lea    mt_voice2(pc),a6
  295.     move.l    mt_samplerep(a6),$b0(a5)
  296.     move.w    mt_samplerepl(a6),$b4(a5)
  297.     lea    mt_voice1(pc),a6
  298.     move.l    mt_samplerep(a6),$a0(a5)
  299.     move.w    mt_samplerepl(a6),$a4(a5)
  300.  
  301.     addq.w    #4,mt_pattpos(a4)
  302.     cmp.w    #$100,mt_pattpos(a4)
  303.     bne.s    mt_endr
  304. mt_nex:    clr.w    mt_pattpos(a4)
  305.     clr.b    mt_break(a4)
  306.     addq.b    #1,mt_songpos(a4)
  307.     and.b    #$7f,mt_songpos(a4)
  308.     move.b    mt_songpos(a4),d1
  309.     move.l    mt_data(a4),a0
  310.     cmp.b    $3b6(a0),d1
  311.     bne.s    mt_endr
  312.     clr.b    mt_songpos(a4)
  313. mt_endr:tst.b    mt_break(a4)
  314.     bne.s    mt_nex
  315. mt_playerror:
  316.     movem.l    (SP)+,d0-d5/a0-a6
  317.     rts
  318.  
  319. mt_waitscan:
  320.     move.b    6(a5),d1
  321. mt_scanloop:
  322.     cmp.b    6(a5),d1
  323.     beq.s    mt_scanloop
  324.     dbf    d3,mt_waitscan
  325.     rts
  326.  
  327. mt_setmyport:
  328.     move.w    mt_cmdperiod(a6),d2
  329.     and.w    #$fff,d2
  330.     move.w    d2,mt_slidedest(a6)
  331.     move.w    mt_period(a6),d0
  332.     clr.b    mt_slidedir(a6)
  333.     cmp.w    d0,d2
  334.     beq.s    mt_clrport
  335.     bge.s    mt_rt
  336.     move.b    #$1,mt_slidedir(a6)
  337.     rts
  338. mt_clrport:
  339.     clr.w    mt_slidedest(a6)
  340. mt_rt:    rts
  341.  
  342. mt_myport:
  343.     move.b    mt_cmdpar(a6),d0
  344.     beq.s    mt_myslide
  345.     move.b    d0,mt_slidespeed(a6)
  346.     clr.b    mt_cmdpar(a6)
  347. mt_myslide:
  348.     tst.w    mt_slidedest(a6)
  349.     beq.s    mt_rt
  350.     moveq    #0,d0
  351.     move.b    mt_slidespeed(a6),d0
  352.     tst.b    mt_slidedir(a6)
  353.     bne.s    mt_mysub
  354.     add.w    d0,mt_period(a6)
  355.     move.w    mt_slidedest(a6),d0
  356.     cmp.w    mt_period(a6),d0
  357.     bgt.s    mt_myok
  358.     move.w    mt_slidedest(a6),mt_period(a6)
  359.     clr.w    mt_slidedest(a6)
  360. mt_myok:move.w    mt_period(a6),$6(a5)
  361.     rts
  362. mt_mysub:
  363.     sub.w    d0,mt_period(a6)
  364.     move.w    mt_slidedest(a6),d0
  365.     cmp.w    mt_period(a6),d0
  366.     blt.s    mt_myok
  367.     move.w    mt_slidedest(a6),mt_period(a6)
  368.     clr.w    mt_slidedest(a6)
  369.     move.w    mt_period(a6),$6(a5)
  370.     rts
  371.  
  372. mt_vib:    move.b    mt_cmdpar(a6),d0
  373.     beq.s    mt_vi
  374.     move.b    d0,mt_vibamp(a6)
  375.  
  376. mt_vi:    move.b    mt_vibcount(a6),d0
  377.     lea    mt_sin(PC),a0
  378.     lsr.w    #$2,d0
  379.     and.w    #$1f,d0
  380.     moveq    #0,d2
  381.     move.b    (a0,d0.w),d2
  382.     move.b    mt_vibamp(a6),d0
  383.     and.w    #$f,d0
  384.     mulu    d0,d2
  385.     lsr.w    #$6,d2
  386.     move.w    mt_period(a6),d0
  387.     tst.b    mt_vibcount(a6)
  388.     bmi.s    mt_vibmin
  389.     add.w    d2,d0
  390.     bra.s    mt_vib2
  391. mt_vibmin:
  392.     sub.w    d2,d0
  393. mt_vib2:move.w    d0,$6(a5)
  394.     move.b    mt_vibamp(a6),d0
  395.     lsr.w    #$2,d0
  396.     and.w    #$3c,d0
  397.     add.b    d0,mt_vibcount(a6)
  398.     rts
  399.  
  400. mt_nop:    move.w    mt_period(a6),$6(a5)
  401.     rts
  402.  
  403. mt_checkcom:
  404.     move.w    mt_cmd(a6),d0
  405.     and.w    #$fff,d0
  406.     beq.s    mt_nop
  407.     move.b    mt_cmd(a6),d0
  408.     and.b    #$f,d0
  409.     tst.b    d0
  410.     beq    mt_arpeggio
  411.     cmp.b    #$1,d0
  412.     beq.s    mt_portup
  413.     cmp.b    #$2,d0
  414.     beq    mt_portdown
  415.     cmp.b    #$3,d0
  416.     beq    mt_myport
  417.     cmp.b    #$4,d0
  418.     beq    mt_vib
  419.     move.w    mt_period(a6),$6(a5)
  420.     cmp.b    #$a,d0
  421.     beq.s    mt_volslide
  422.     rts
  423.  
  424. mt_volslide:
  425.     moveq    #0,d0
  426.     move.b    mt_cmdpar(a6),d0
  427.     lsr.b    #4,d0
  428.     tst.b    d0
  429.     beq.s    mt_voldown
  430.     add.w    d0,mt_volume(a6)
  431.     cmp.w    #$40,mt_volume(a6)
  432.     bmi.s    mt_vol2
  433.     move.w    #$40,mt_volume(a6)
  434. mt_vol2:move.w    mt_volume(a6),$8(a5)
  435.     rts
  436.  
  437. mt_voldown:
  438.     moveq    #0,d0
  439.     move.b    mt_cmdpar(a6),d0
  440.     and.b    #$f,d0
  441.     sub.w    d0,mt_volume(a6)
  442.     bpl.s    mt_vol3
  443.     clr.w    mt_volume(a6)
  444. mt_vol3:move.w    mt_volume(a6),$8(a5)
  445.     rts
  446.  
  447. mt_portup:
  448.     moveq    #0,d0
  449.     move.b    mt_cmdpar(a6),d0
  450.     sub.w    d0,mt_period(a6)
  451.     move.w    mt_period(a6),d0
  452.     and.w    #$fff,d0
  453.     cmp.w    #$71,d0
  454.     bpl.s    mt_por2
  455.     and.w    #$f000,mt_period(a6)
  456.     or.w    #$71,mt_period(a6)
  457. mt_por2:move.w    mt_period(a6),d0
  458.     and.w    #$fff,d0
  459.     move.w    d0,$6(a5)
  460.     rts
  461.  
  462. mt_portdown:
  463.     clr.w    d0
  464.     move.b    mt_cmdpar(a6),d0
  465.     add.w    d0,mt_period(a6)
  466.     move.w    mt_period(a6),d0
  467.     and.w    #$fff,d0
  468.     cmp.w    #$358,d0
  469.     bmi.s    mt_por3
  470.     and.w    #$f000,mt_period(a6)
  471.     or.w    #$358,mt_period(a6)
  472. mt_por3:move.w    mt_period(a6),d0
  473.     and.w    #$fff,d0
  474.     move.w    d0,$6(a5)
  475.     rts
  476.  
  477. mt_checkcom2:
  478.     move.b    mt_cmd(a6),d0
  479.     and.b    #$f,d0
  480.     cmp.b    #$e,d0
  481.     beq.s    mt_setfilt
  482.     cmp.b    #$d,d0
  483.     beq.s    mt_pattbreak
  484.     cmp.b    #$b,d0
  485.     beq.s    mt_posjmp
  486.     cmp.b    #$c,d0
  487.     beq.s    mt_setvol
  488.     cmp.b    #$f,d0
  489.     beq.s    mt_setspeed
  490.     rts
  491.  
  492. mt_setfilt:
  493.     move.b    mt_cmdpar(a6),d0
  494.     and.b    #1,d0
  495.     add.b    d0,d0
  496.     and.b    #$fd,$bfe001
  497.     or.b    d0,$bfe001
  498.     rts
  499. mt_pattbreak:
  500.     st    mt_break(a4)
  501.     rts
  502. mt_posjmp:
  503.     move.b    mt_cmdpar(a6),d0
  504.     subq.b    #1,d0
  505.     move.b    d0,mt_songpos(a4)
  506.     st    mt_break(a4)
  507.     rts
  508. mt_setvol:
  509.     cmp.b    #$40,mt_cmdpar(a6)
  510.     ble.s    mt_vol4
  511.     move.b    #$40,mt_cmdpar(a6)
  512. mt_vol4:move.b    mt_cmdpar(a6),$8(a5)
  513.     rts
  514. mt_setspeed:
  515.     move.b    mt_cmdpar(a6),d0
  516.     and.w    #$ff,d0
  517.     beq.s    mt_rts2
  518.     move.b    d0,d1
  519.     and.b    #$f0,d1
  520.     beq.s    mt_speed1
  521.     lsr.b    #4,d1
  522.     bra.s    mt_speed3
  523. mt_speed1:
  524.     move.b    d0,d1
  525. mt_speed3:
  526.     and.b    #$f,d0
  527.     bne.s    mt_speed2
  528.     move.b    d1,d0
  529. mt_speed2:
  530.     move.b    d0,mt_speedEven(a4)
  531.     move.b    d1,mt_speedOdd(a4)
  532.     clr.b    mt_counter(a4)
  533. mt_rts2:rts
  534.  
  535. mt_sin:
  536.     dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  537.     dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  538.  
  539. mt_periods:
  540.     dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  541.     dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  542.     dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  543.     dc.w $007f,$0078,$0071,$0000,$0000
  544.  
  545. mt_playerdata:    blk.b    mt_datalen,0
  546. mt_samplestarts:blk.l    31,0
  547. mt_voice1:    blk.b    mt_voicelen,0
  548. mt_voice2:    blk.b    mt_voicelen,0
  549. mt_voice3:    blk.b    mt_voicelen,0
  550. mt_voice4:    blk.b    mt_voicelen,0
  551.  
  552.